<?php
include_once("../../untils/conn.php");
$proxy_acc = $_POST['proxy_acc'];
$proxy_pass = $_POST['proxy_password'];
$proxy_phone =$_POST['proxy_phone'];
$proxy_name = $_POST['proxy_name'];
$proxy_rename = $_POST['proxy_rename'];
$proxy_uid  = $_POST['proxy_uid'];
$proxy_rename_sta = 1;
$proxy_type = $_POST['proxy_type'];
$group_id =$_POST['group_id'];
$cr_time = $_POST['cr_time'];
// 查询proxy数据表中是否存在相同的proxy_acc值
$sql = "SELECT * FROM proxy WHERE proxy_acc = '$proxy_acc'";
$result = mysqli_query($con, $sql);

if(mysqli_num_rows($result) > 0) {
  // 如果查询结果不为空，则说明该账号已存在，返回提示信息
   echo "<script>alert('该账号已存在，请重新添加');</script>";
    echo ("<script>window.location.href='../proxylist.php'</script>");
} else {
  // 如果查询结果为空，则可以执行INSERT语句将数据写入数据库
  $sql = "INSERT INTO proxy (proxy_acc, proxy_pass, proxy_phone, proxy_name, proxy_rename, proxy_uid, proxy_rename_sta, proxy_type, cr_time, group_id) VALUES ('$proxy_acc', '$proxy_pass','$proxy_phone','$proxy_name','$proxy_rename','$proxy_uid','$proxy_rename_sta','$proxy_type','$cr_time','$group_id')";
  if(mysqli_query($con, $sql)) {
    $proxy_id = mysqli_insert_id($con); // 获取刚刚插入数据的自增ID
    // 将proxy_id插入到shopsy表中的puid字段中
    $sql = "INSERT INTO shopsy (puid) VALUES ('$proxy_id')";
    mysqli_query($con, $sql);
    echo "<script>alert('提交成功');</script>";
    echo ("<script>window.location.href='../proxylist.php'</script>");
  } else {
     echo "<script>alert('好像发送了意外，请稍后再试');</script>";
     echo ("<script>window.location.href='../proxylist.php'</script>");
    // echo "Error updating record: " . $con->error;
  }
}

?>
